package com.gao.modules.email;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class Email {
    @Autowired
    private JavaMailSender javaMailSender;

    public String sendEmail(String toName,
                            String title,
                            String text){

        try {
            SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
            simpleMailMessage.setFrom("1181810576@qq.com");
            simpleMailMessage.setTo(toName);
            simpleMailMessage.setSubject(title);
            simpleMailMessage.setText(text);
            javaMailSender.send(simpleMailMessage);
        }catch (Exception e){
            e.printStackTrace();
            return "文件发送失败，请检查输入的邮箱是否正确";

        }
        return "发送成功";
    }
}
